#include #define address 0x35 int16_t x, y, z; int16_t temp; void setup() { Serial.begin(115200); Wire.begin(); Wire.setClock(400000); // --- Reset sequence --- Wire.beginTransmission(0); Wire.write(0xFF); Wire.endTransmission(); Wire.beginTransmission(0); Wire.write(0xFF); Wire.endTransmission(); Wire.beginTransmission(0); Wire.write(0x00); Wire.endTransmission(); Wire.beginTransmission(0); Wire.write(0x00); Wire.endTransmission(); delayMicroseconds(50); // --- Configure sensor --- Wire.beginTransmission(address); Wire.write(0x10); Wire.write(0x28); // config Wire.write(0x15); // mode Wire.endTransmission(); delay(100); } void loop() { uint8_t v0, v1, v2, v3, v4, v5; // --- Read 6 bytes --- Wire.requestFrom(address, 6); if (Wire.available() == 6) { v0 = Wire.read(); v1 = Wire.read(); v2 = Wire.read(); v3 = Wire.read(); v4 = Wire.read(); v5 = Wire.read(); // --- Decode 12-bit signed values --- x = ((int16_t)v0 << 4) | (v4 >> 4); y = ((int16_t)v1 << 4) | (v4 & 0x0F); z = ((int16_t)v2 << 4) | (v5 & 0x0F); // --- Sign correction (12-bit signed) --- if (x & 0x800) x -= 4096; if (y & 0x800) y -= 4096; if (z & 0x800) z -= 4096; // --- Temperature (optional rough value) --- temp = v3; // --- Print readable output --- Serial.print("X: "); Serial.print(x); Serial.print(" | Y: "); Serial.print(y); Serial.print(" | Z: "); Serial.print(z); Serial.print(" | Temp: "); Serial.println(temp); } delay(100); // readable rate }